using Prime31;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LaserSkill : abstuctSkill
{
    //受击后的弹跳范围
    public float hitBounce = 10;
    protected override void onExecute()
    {
        //throw new System.NotImplementedException();
    }
    protected override void onFrontDurationStart()
    {
        base.onFrontDurationStart();
        this.initialTransform = source.transform.GetChild(0).transform;
        this.gameObject.transform.position = initialTransform.position;
        if (source.transform.localScale.x < 0)
        {
            setDirection(new Vector3(-1, 0, 0));

        }
        else
        {
            setDirection(new Vector3(1, 0, 0));

        }
        this.gameObject.SetActive(true);
    }
    /// <summary>
    /// 设置技能的释放方向,在释放技能前设置
    /// </summary>
    /// <param name="direction"></param>
    private  void setDirection(Vector3 direction)
    {
        this.direction = direction;
        if (direction.x < 0)
        {
            //this.GetComponent<SpriteRenderer>().flipX = true;
            this.gameObject.transform.localScale = -this.gameObject.transform.localScale;

        }
    }
    //// Start is called before the first frame update
    //void Start()
    //{

    //}

    // Update is called once per frame
    void Update()
    {
        if (source.tag != "Player") { return; }

        this.gameObject.transform.position = source.transform.GetChild(0).transform.position;
    }
    public void OnTriggerEnter2D(Collider2D collision)
    {
        Debug.Log(" gameObject:" + collision.gameObject.name);
        if (source != collision.gameObject && collision.gameObject.tag == "Player")
        {
            //this.GetComponent<BoxCollider2D>().enabled = false;
            if (this.gameObject.transform.localScale.x > 0)
            {
                collision.gameObject.GetComponent<playerControl>()._velocity += new Vector3(hitBounce, 3, 0);
            }
            else
            {
                collision.gameObject.GetComponent<playerControl>()._velocity += new Vector3(-hitBounce, 3, 0);

            }
            collision.gameObject.GetComponent<playerControl>().hit(this.source, basicDamage);


        }

    }
    public void onFinished()
    {
        Destroy(gameObject);
    }
}
